home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / ghostscript / 8.64 / lib / mkcidfm.ps < prev    next >
Encoding:
Text File  |  2009-04-17  |  7.1 KB  |  360 lines

  1. % Copyright (C) 2004 Artifex Software, Inc. All rights reserved.
  2. % This software is provided AS-IS with no warranty, either express or
  3. % implied.
  4. % This software is distributed under license and may not be copied,
  5. % modified or distributed except as expressly authorized under the terms
  6. % of the license contained in the file LICENSE in this distribution.
  7. % For more information about licensing, please refer to
  8. % http://www.ghostscript.com/licensing/. For information on
  9. % commercial licensing, go to http://www.artifex.com/licensing/ or
  10. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. % San Rafael, CA  94903, U.S.A., +1(415)492-9861.
  12.  
  13. % $Id: mkcidfm.ps 8022 2007-06-05 22:23:38Z giles $
  14.  
  15. % Generate a cidfmap file for substituting CID fonts with TrueType 
  16. % fonts, based on fonts found in the directory FONTDIR.
  17. % The directory FONTDIR is searched for fonts whose filename
  18. % matches a Path in the cidsubs dictionary.
  19. % Any matches are written out as a CID font substitution.
  20. %
  21. % For each fontname and alias in the fontaliases dictionary,
  22. % write out each alias that matches a substituted font.
  23. % Where multiple aliases are possible, use the first match.
  24. %
  25. % Note that the substitutions and aliases in this file were created 
  26. % by someone who doesn't understand Chinese, Japanese or Korean.  
  27. % The initial list contains only font files found in Windows XP.
  28. % Please submit corrections and additions.
  29. %
  30. % Font filenames must match case.  
  31. % All font filenames are currently lower case.
  32. %
  33. % Usage: gswin32c -q -dBATCH -sFONTDIR=c:/windows/fonts
  34. %                -sCIDFMAP=c:/gs/cidfmap mkcidfm.ps
  35.  
  36.  
  37. systemdict /FONTDIR known not { /FONTDIR (c:/windows/fonts) def } if
  38.  
  39. systemdict /CIDFMAP known { CIDFMAP } { (%stdout) } ifelse
  40. /cidfmap exch (w) file def
  41.  
  42. % Directory separator as used by filenameforall
  43. /dirsep (/) def
  44.  
  45. % This dictionary contains a list of font substitutions.
  46. % The first matching substitution in the array will be used.
  47. /fontaliases
  48. <<
  49.   % Traditional Chinese
  50.   /MSung-Light [ /MingLiU ]
  51.   /MSung-Medium [ /MingLiU ]
  52.   /MHei-Medium [ /MingLiU ]
  53.   /MKai-Medium [ /Arial-Unicode-MS /MingLiU ]
  54.  
  55.   % Simplified Chinese
  56.   /STSong-Light [ /SimSun ]
  57.   /STFangsong-Light [ /SimSun ]
  58.   /STHeiti-Regular [ /SimHei ]
  59.   /STKaiti-Regular [ /SimHei ]
  60.  
  61.   % Japanese
  62.   /Ryumin-Light [ /MS-Mincho ]
  63.   /Ryumin-Medium [ /MS-Mincho ]
  64.   /GothicBBB-Medium [ /MS-Gothic ]
  65.   /HeiseiMin-W3 [ /MS-Mincho ]
  66.   /HeiseiKakuGo-W5 [ /MS-Gothic ]
  67.  
  68.   % Korean
  69.   /HYSMyeongJo-Medium [ /Batang ]
  70.   /HYRGoThic-Medium [ /Gulim ]
  71.   /HYGoThic-Medium [ /Dotum ]
  72. >>
  73. def
  74.  
  75.  
  76. % This dictionary contains a list of CID substitutions
  77. /cidsubs 
  78. <<
  79.   % Simplified Chinese
  80.   /SimHei
  81.   <<
  82.    /FileType /TrueType
  83.    /Path (simhei.ttf)
  84.    /SubfontID 0
  85.    /CSI [(GB1) 2]
  86.   >>
  87.  
  88.   /SimSun
  89.   <<
  90.    /FileType /TrueType
  91.    /Path (simsun.ttc)
  92.    /SubfontID 0
  93.    /CSI [(GB1) 2]
  94.   >>
  95.  
  96.   /NSimSun
  97.   <<
  98.    /FileType /TrueType
  99.    /Path (simsun.ttc)
  100.    /SubfontID 1
  101.    /CSI [(GB1) 2]
  102.   >>
  103.  
  104.   % Traditional Chinese
  105.   /MingLiU
  106.   <<
  107.    /FileType /TrueType
  108.    /Path (mingliu.ttc)
  109.    /SubfontID 0
  110.    /CSI [(CNS1) 2]
  111.   >>
  112.  
  113.   /PMingLiU
  114.   <<
  115.    /FileType /TrueType
  116.    /Path (mingliu.ttc)
  117.    /SubfontID 1
  118.    /CSI [(CNS1) 2]
  119.   >>
  120.  
  121.   /Arial-Unicode-MS
  122.   <<
  123.    /FileType /TrueType
  124.    /Path (arialuni.ttc)
  125.    /SubfontID 0
  126.    /CSI [(CNS1) 2]
  127.   >>
  128.  
  129.   % Japanese
  130.   /MS-Gothic
  131.   <<
  132.    /FileType /TrueType
  133.    /Path (msgothic.ttc)
  134.    /SubfontID 0
  135.    /CSI [(Japan1) 3]
  136.   >>
  137.  
  138.   /MS-PGothic
  139.   <<
  140.    /FileType /TrueType
  141.    /Path (msgothic.ttc)
  142.    /SubfontID 1
  143.    /CSI [(Japan1) 3]
  144.   >>
  145.  
  146.   /MS-UI-Gothic
  147.   <<
  148.    /FileType /TrueType
  149.    /Path (msgothic.ttc)
  150.    /SubfontID 2
  151.    /CSI [(Japan1) 3]
  152.   >>
  153.  
  154.   /MS-Mincho
  155.   <<
  156.    /FileType /TrueType
  157.    /Path (msmincho.ttc)
  158.    /SubfontID 0
  159.    /CSI [(Japan1) 3]
  160.   >>
  161.  
  162.   /MS-PMincho
  163.   <<
  164.    /FileType /TrueType
  165.    /Path (msmincho.ttc)
  166.    /SubfontID 1
  167.    /CSI [(Japan1) 3]
  168.   >>
  169.  
  170.   % Korean
  171.   /Batang
  172.   <<
  173.    /FileType /TrueType
  174.    /Path (batang.ttc)
  175.    /SubfontID 0
  176.    /CSI [(Korea1) 3]
  177.   >>
  178.  
  179.   /BatangChe
  180.   <<
  181.    /FileType /TrueType
  182.    /Path (batang.ttc)
  183.    /SubfontID 1
  184.    /CSI [(Korea1) 3]
  185.   >>
  186.  
  187.   /Gungsuh
  188.   <<
  189.    /FileType /TrueType
  190.    /Path (batang.ttc)
  191.    /SubfontID 2
  192.    /CSI [(Korea1) 3]
  193.   >>
  194.  
  195.   /GungsuhChe
  196.   <<
  197.    /FileType /TrueType
  198.    /Path (batang.ttc)
  199.    /SubfontID 3
  200.    /CSI [(Korea1) 3]
  201.   >>
  202.  
  203.   /Gulim
  204.   <<
  205.    /FileType /TrueType
  206.    /Path (gulim.ttc)
  207.    /SubfontID 0
  208.    /CSI [(Korea1) 3]
  209.   >>
  210.  
  211.   /GulimChe
  212.   <<
  213.    /FileType /TrueType
  214.    /Path (gulim.ttc)
  215.    /SubfontID 1
  216.    /CSI [(Korea1) 3]
  217.   >>
  218.  
  219.   /Dotum
  220.   <<
  221.    /FileType /TrueType
  222.    /Path (gulim.ttc)
  223.    /SubfontID 2
  224.    /CSI [(Korea1) 3]
  225.   >>
  226.  
  227.   /DotumChe
  228.   <<
  229.    /FileType /TrueType
  230.    /Path (gulim.ttc)
  231.    /SubfontID 3
  232.    /CSI [(Korea1) 3]
  233.   >>
  234.  
  235. >>
  236. def
  237.  
  238.  
  239. % A dictionary for storing the names and paths of found fonts
  240. /foundfonts 50 dict def
  241.  
  242. % Get the basename of a path
  243. % For example, (c:/windows/fonts/msmincho.ps) --> (msmincho.ps)
  244. /basename { % path -- subpath
  245.   { dirsep search
  246.     {pop pop}
  247.     {exit}
  248.     ifelse
  249.   } loop
  250. } def
  251.  
  252.  
  253. % Check if a font basename matches one of the possible cid substitutions.  
  254. % If it does, add the font and full path to the foundfonts dictionary
  255. /checkfont {
  256.   dup basename
  257.   cidsubs
  258.   {
  259.     /Path get
  260.     2 index eq  % Match case only
  261.     {
  262.       foundfonts exch
  263.       3 index dup length string copy put
  264.     }
  265.     {
  266.       pop
  267.     }
  268.     ifelse
  269.   }
  270.   forall
  271.   pop pop
  272. } def
  273.  
  274. % Add all matching fonts to foundfonts dictionary
  275. /findfonts { % path --
  276.   dup length 2 add string dup 3 1 roll copy pop
  277.   dup dup length 2 sub dirsep 0 get put
  278.   dup dup length 1 sub (*) 0 get put
  279.   /checkfont load 256 string filenameforall
  280. } def
  281.  
  282.  
  283. % Write out a cid substition, using the full font path
  284. % name is the font name, e.g. /MS-Mincho
  285. % path is the full path to the font file, e.g. (c:\windows\fonts\msmincho.ps)
  286. % subs is the dictionary for CID font substition, from cidsubs
  287. /emitsubs { % name path subs -- 
  288.   3 -1 roll cidfmap exch write==only % name
  289.   cidfmap ( << ) writestring
  290.   % path subs
  291.   {
  292.    1 index /Path eq {pop 1 index} if % use full path, not basename
  293.    exch cidfmap exch write==only cidfmap ( ) writestring 
  294.    cidfmap exch write==only cidfmap ( ) writestring 
  295.   } forall
  296.   cidfmap (>> ;\n) writestring
  297.   pop
  298. } def
  299.  
  300. % Write out all known cid substitutions.
  301. /writesubs { % ---
  302.   cidfmap (% Substitutions\n) writestring
  303.   foundfonts
  304.   {
  305.     1 index cidsubs exch known
  306.     {
  307.       1 index cidsubs exch get % name path subs
  308.       emitsubs
  309.     }
  310.     {
  311.       pop pop
  312.     }
  313.     ifelse
  314.   }
  315.   forall
  316. } def
  317.  
  318. % Write out aliases for which the cid substituted font exists.
  319. /writealiases { % --
  320.   cidfmap (\n% Aliases\n) writestring
  321.   fontaliases 
  322.   {
  323.     % name aliasarray
  324.     {
  325.       % name alias
  326.       foundfonts 1 index known
  327.       {
  328.     1 index cidfmap exch write==only cidfmap ( ) writestring 
  329.     cidfmap exch write==only cidfmap ( ;\n) writestring
  330.     exit % after first match
  331.       }
  332.       {
  333.     pop % didn't find this name
  334.       }
  335.       ifelse
  336.     } forall
  337.     % name
  338.     pop
  339.   }
  340.   forall
  341. } def
  342.  
  343.  
  344. % Write out a new cidfmap file to stdout
  345. /writecidfmap { % path --
  346.   cidfmap (%!\n% cidfmap generated automatically by mkcidfm.ps from fonts found in\n) writestring
  347.   cidfmap (%   ) writestring
  348.   dup cidfmap exch writestring cidfmap (\n\n) writestring
  349.   findfonts
  350.   writesubs
  351.   writealiases
  352. } def
  353.  
  354.  
  355. FONTDIR writecidfmap
  356.